package ynu.edu.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ynu.edu.dao.ICourseDao;
import ynu.edu.po.Course;

import java.util.Optional;

@RestController
@RequestMapping(value = "/cou")
@Tag(name="课程信息相关服务")
public class CourseController {
    @Resource
    private ICourseDao cDao;

    @Operation(summary = "Hello测试方法")
    @GetMapping(value = "/hello")
    public String hello() {
        return "Course Controller";
    }

    @Operation(summary = "获取课程信息")
    @Parameter(name="couId",description = "课程唯一标识")
    @GetMapping(value = "/getCourseInfo/{couId}")
    public Course getCourseInfo(@PathVariable("couId") String couId) {
        Long courseId = Long.parseLong(couId);
        Optional<Course> result= cDao.findById(courseId);
        return result.orElse(null);
    }


}
